<!DOCTYPE html>




<html class="theme-next gemini" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />






















<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=6.0.0" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=6.0.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=6.0.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=6.0.0">


  <link rel="mask-icon" href="/images/logo.svg?v=6.0.0" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="Blog本博客纯属个人经验分享，不是技术博客，请大佬们多多指教 Reputation无名之辈 ContactWechat: wanli249259Email: 15070926843@163.com">
<meta property="og:type" content="website">
<meta property="og:title" content="About">
<meta property="og:url" content="http://wlccgp3.coding.me/about/index.html">
<meta property="og:site_name" content="Just Do It">
<meta property="og:description" content="Blog本博客纯属个人经验分享，不是技术博客，请大佬们多多指教 Reputation无名之辈 ContactWechat: wanli249259Email: 15070926843@163.com">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-01-27T07:02:54.611Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="About">
<meta name="twitter:description" content="Blog本博客纯属个人经验分享，不是技术博客，请大佬们多多指教 Reputation无名之辈 ContactWechat: wanli249259Email: 15070926843@163.com">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '6.0.0',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: false,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://wlccgp3.coding.me/about/"/>





  <title>Git学习笔记 | Just Do It</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
    <a href="https://git.coding.net/wlccgp3/wlccgp3.coding.me.git">
      <img style="position: absolute; top: 0; right: 0; border: 0;" src="/images/forkme_light_background_right.png">
    </a>

    

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"> <div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Just Do It</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">我思故我在</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            

            
              首页
            

          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            

            
              归档
            

          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            

            
              关于
            

          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            

            
              标签
            

          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            

            
              分类
            

          </a>
        </li>
      
        
        <li class="menu-item menu-item-python3学习笔记">
          <a href="/python3学习笔记/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-book"></i> <br />
            

            
              python3学习笔记
            

          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://wlccgp3.coding.me/notebook/Git.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="丿我欲疾风前行灬">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Just Do It">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Git学习笔记</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-01-27T11:03:41+08:00">2018-01-27</time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/笔记/" itemprop="url" rel="index">
                    <span itemprop="name">笔记</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/notebook/Git.html#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count"
                        data-disqus-identifier="notebook/Git.html" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/notebook/Git.html" class="leancloud_visitors" data-flag-title="Git学习笔记">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="初始化配置"><a href="#初始化配置" class="headerlink" title="初始化配置"></a>初始化配置</h3><pre><code>git config --global user.email &apos;1301281985@qq.com&apos;
git config --global user.name &apos;wanli&apos;
git config --global credential.helper store
</code></pre><h3 id="git-status中文显示问题"><a href="#git-status中文显示问题" class="headerlink" title="git status中文显示问题"></a>git status中文显示问题</h3><pre><code>git config --global core.quotepath false
</code></pre><h3 id="指定编辑器"><a href="#指定编辑器" class="headerlink" title="指定编辑器"></a>指定编辑器</h3><pre><code>git config --global core.editor vim
</code></pre><h3 id="生成秘钥"><a href="#生成秘钥" class="headerlink" title="生成秘钥"></a>生成秘钥</h3><pre><code>ssh-keygen -t rsa -C &apos;1301281985@qq.com&apos;
</code></pre><h3 id="加入到known-hosts"><a href="#加入到known-hosts" class="headerlink" title="加入到known_hosts"></a>加入到known_hosts</h3><pre><code>ssh -vT git@git.coding.net
</code></pre><h3 id="一般流程"><a href="#一般流程" class="headerlink" title="一般流程"></a>一般流程</h3><pre><code>mkdir -p dirname
git init
git remote add gitrep(本地仓库名) https://...(远程仓库地址)
git push -u gitrep master
    -u：以后的push可以直接用git push默认只推送当前分支
</code></pre><h3 id="push和pull出现的问题"><a href="#push和pull出现的问题" class="headerlink" title="push和pull出现的问题"></a>push和pull出现的问题</h3><pre><code>fatal: refusing to merge unrelated histories或者fatal: 拒绝合并无关的历史
git push -f -u [本地如origin] [远程如master]
git pull [远程origin] [远程master] --allow-unrelated-histories
</code></pre><h3 id="push出现Failed-to-connect-to-127-0-0-1-port-37956-拒绝连接"><a href="#push出现Failed-to-connect-to-127-0-0-1-port-37956-拒绝连接" class="headerlink" title="push出现Failed to connect to 127.0.0.1 port 37956: 拒绝连接"></a>push出现Failed to connect to 127.0.0.1 port 37956: 拒绝连接</h3><pre><code>env|rg &apos;proxy&apos;可以看到https使用了代理，与lantern有关
unset https_proxy http_proxy
</code></pre><h3 id="撤销git-add"><a href="#撤销git-add" class="headerlink" title="撤销git add"></a>撤销git add</h3><pre><code>git reset HEAD file/dir
</code></pre><h3 id="忽略特定文件夹和文件"><a href="#忽略特定文件夹和文件" class="headerlink" title="忽略特定文件夹和文件"></a>忽略特定文件夹和文件</h3><pre><code>在git仓库的根目录创建.gitignore文件
</code></pre><h3 id="返回旧版本"><a href="#返回旧版本" class="headerlink" title="返回旧版本"></a>返回旧版本</h3><pre><code>先用 git log -g 查看版本
然后git reset --hard 3628164  # 最后是commit版本号
</code></pre><h3 id="如果返回旧版本，而且又关了电脑，现在又想回到新版本"><a href="#如果返回旧版本，而且又关了电脑，现在又想回到新版本" class="headerlink" title="如果返回旧版本，而且又关了电脑，现在又想回到新版本"></a>如果返回旧版本，而且又关了电脑，现在又想回到新版本</h3><pre><code>git reflog 用来记录每一个命令，可以看到提交的版本信息
git reset --hard commit_id  # commit_id可以缩写
</code></pre><h3 id="放弃本地所有修改重新拉取远程仓库"><a href="#放弃本地所有修改重新拉取远程仓库" class="headerlink" title="放弃本地所有修改重新拉取远程仓库"></a>放弃本地所有修改重新拉取远程仓库</h3><pre><code>git fetch --all
git reset --hard origin/master 
git pull
</code></pre><h3 id="改乱了工作区某个文件的内容，想直接丢弃工作区的修改时"><a href="#改乱了工作区某个文件的内容，想直接丢弃工作区的修改时" class="headerlink" title="改乱了工作区某个文件的内容，想直接丢弃工作区的修改时"></a>改乱了工作区某个文件的内容，想直接丢弃工作区的修改时</h3><pre><code>git checkout -- file
git checkout其实是用版本库里的版本替换工作区的版本，无论工作区是修改还是删除，都可以“一键还原”
</code></pre><h3 id="电脑配置的公钥长时间不适用可能会失效，要重新添加到git远程公钥中"><a href="#电脑配置的公钥长时间不适用可能会失效，要重新添加到git远程公钥中" class="headerlink" title="电脑配置的公钥长时间不适用可能会失效，要重新添加到git远程公钥中"></a>电脑配置的公钥长时间不适用可能会失效，要重新添加到git远程公钥中</h3><h3 id="vscode点击同步时出现冲突，解决方法："><a href="#vscode点击同步时出现冲突，解决方法：" class="headerlink" title="vscode点击同步时出现冲突，解决方法："></a>vscode点击同步时出现冲突，解决方法：</h3><pre><code>- F1打开命令菜单，git merge 选择orign/master --&gt; 处理冲突后commit --&gt; git push
</code></pre><h3 id="修改-gitignore文件-不生效"><a href="#修改-gitignore文件-不生效" class="headerlink" title="修改.gitignore文件 不生效"></a>修改.gitignore文件 不生效</h3><p>原因是.gitignore只能忽略那些原来没有被track的文件，如果某些文件已经被纳入了版本管理中，则修改.gitignore是无效的。<br>那么解决方法就是先把本地缓存删除（改变成未track状态），然后再提交：<br>    git rm -r –cached .<br>    git add .<br>    git commit -m ‘update .gitignore’</p>
<h3 id="git撤销删除分支"><a href="#git撤销删除分支" class="headerlink" title="git撤销删除分支"></a>git撤销删除分支</h3><pre><code>git log -g 找到该分支的最后一次操作，记下commit_id
git checkout -b [branch-name] [commit-id]
</code></pre><h3 id="git-push"><a href="#git-push" class="headerlink" title="git push"></a>git push</h3><ul>
<li>git push [远程仓库名] [本地分支名]:[远程分支名]</li>
</ul>
<p>如果本地分支名和远程分支名一样，则：</p>
<ul>
<li>git push [远程仓库名] [分支名]</li>
</ul>
<h4 id="git-push-多个远程仓库"><a href="#git-push-多个远程仓库" class="headerlink" title="git push 多个远程仓库"></a>git push 多个远程仓库</h4><pre><code>git remote add origin &lt;github-url&gt;
git remote set-url --add origin &lt;coding-url&gt;
</code></pre><h3 id="git-remote"><a href="#git-remote" class="headerlink" title="git remote"></a>git remote</h3><pre><code>git remote -v  查看是否连接上服务器仓库
git remote  查看仓库名称
git remote add [远程仓库名]  https://......（仓库https 地址）
git remote remove [远程仓库名]  移除该仓库名连接
</code></pre><h3 id="分支管理"><a href="#分支管理" class="headerlink" title="分支管理"></a>分支管理</h3><pre><code>git branch -d [branch-name]           # 删除本地分支，-D强制删除
git branch -vv                        # 查看所有分支的详细信息
git checkout -b [oldName]             # 创建oldName，并切换到该分支
git branch -m [oldName] [newName]     # 重命名分支
git push --delete [origin] [oldName]  # 删除已有的远程分支
</code></pre>
      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>随意</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechatpay.png" alt="丿我欲疾风前行灬 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.jpg" alt="丿我欲疾风前行灬 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/git/" <i class="fa fa-tag"></i> git</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/notebook/Docker.html" rel="next" title="Docker学习笔记">
                <i class="fa fa-chevron-left"></i> Docker学习笔记
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog_post/学习路线.html" rel="prev" title="学习路线">
                学习路线 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="disqus_thread">
        <noscript>
          Please enable JavaScript to view the
          <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a>
        </noscript>
      </div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/avatar.png"
                alt="丿我欲疾风前行灬" />
            
              <p class="site-author-name" itemprop="name">丿我欲疾风前行灬</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives/">
                
                    <span class="site-state-item-count">8</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  <a href="/categories/index.html">
                    <span class="site-state-item-count">2</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  <a href="/tags/index.html">
                    <span class="site-state-item-count">8</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/wlccgp3" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#初始化配置"><span class="nav-number">1.</span> <span class="nav-text">初始化配置</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git-status中文显示问题"><span class="nav-number">2.</span> <span class="nav-text">git status中文显示问题</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#指定编辑器"><span class="nav-number">3.</span> <span class="nav-text">指定编辑器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#生成秘钥"><span class="nav-number">4.</span> <span class="nav-text">生成秘钥</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#加入到known-hosts"><span class="nav-number">5.</span> <span class="nav-text">加入到known_hosts</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#一般流程"><span class="nav-number">6.</span> <span class="nav-text">一般流程</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#push和pull出现的问题"><span class="nav-number">7.</span> <span class="nav-text">push和pull出现的问题</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#push出现Failed-to-connect-to-127-0-0-1-port-37956-拒绝连接"><span class="nav-number">8.</span> <span class="nav-text">push出现Failed to connect to 127.0.0.1 port 37956: 拒绝连接</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#撤销git-add"><span class="nav-number">9.</span> <span class="nav-text">撤销git add</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#忽略特定文件夹和文件"><span class="nav-number">10.</span> <span class="nav-text">忽略特定文件夹和文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#返回旧版本"><span class="nav-number">11.</span> <span class="nav-text">返回旧版本</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#如果返回旧版本，而且又关了电脑，现在又想回到新版本"><span class="nav-number">12.</span> <span class="nav-text">如果返回旧版本，而且又关了电脑，现在又想回到新版本</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#放弃本地所有修改重新拉取远程仓库"><span class="nav-number">13.</span> <span class="nav-text">放弃本地所有修改重新拉取远程仓库</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#改乱了工作区某个文件的内容，想直接丢弃工作区的修改时"><span class="nav-number">14.</span> <span class="nav-text">改乱了工作区某个文件的内容，想直接丢弃工作区的修改时</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#电脑配置的公钥长时间不适用可能会失效，要重新添加到git远程公钥中"><span class="nav-number">15.</span> <span class="nav-text">电脑配置的公钥长时间不适用可能会失效，要重新添加到git远程公钥中</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#vscode点击同步时出现冲突，解决方法："><span class="nav-number">16.</span> <span class="nav-text">vscode点击同步时出现冲突，解决方法：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#修改-gitignore文件-不生效"><span class="nav-number">17.</span> <span class="nav-text">修改.gitignore文件 不生效</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git撤销删除分支"><span class="nav-number">18.</span> <span class="nav-text">git撤销删除分支</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git-push"><span class="nav-number">19.</span> <span class="nav-text">git push</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#git-push-多个远程仓库"><span class="nav-number">19.1.</span> <span class="nav-text">git push 多个远程仓库</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git-remote"><span class="nav-number">20.</span> <span class="nav-text">git remote</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#分支管理"><span class="nav-number">21.</span> <span class="nav-text">分支管理</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="/lib/busuanzi.mini.js"></script>
<div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">丿我欲疾风前行灬</span>

  

  
</div>

<div class="powered-by">
  <i class="fa fa-user-md"></i>
  <span id="busuanzi_container_site_uv">
    本站访客数: <span id="busuanzi_value_site_uv"></span>
  </span>
</div>


  <span class="post-meta-divider">|</span>


<span>Hosted by <a href="https://pages.coding.me" style="font-weight: bold">Coding Pages</a></span>



        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=6.0.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=6.0.0"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=6.0.0"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=6.0.0"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=6.0.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=6.0.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=6.0.0"></script>



  


  

    
      <script id="dsq-count-scr" src="https://wlccgp3.disqus.com/count.js" async></script>
    

    
      <script type="text/javascript">
        var disqus_config = function () {
          this.page.url = 'http://wlccgp3.coding.me/notebook/Git.html';
          this.page.identifier = 'notebook/Git.html';
          this.page.title = 'Git学习笔记';
        };
        var d = document, s = d.createElement('script');
        s.src = 'https://wlccgp3.disqus.com/embed.js';
        s.setAttribute('data-timestamp', '' + +new Date());
        (d.head || d.body).appendChild(s);
      </script>
    

  




	





  














  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("nkWngFx2wKbP8thDk9UKNb25-gzGzoHsz", "pc94NLAzuzjWKWQ8Co27zRRK");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  
  

  

  

  

</body>
</html>
